package com.sluggard.workflow.entity.res;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.camunda.bpm.engine.impl.persistence.entity.DeploymentEntity;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.Objects;

@Data
public class DeploymentResponse {

    private String Id;

    private String name;

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date deploymentTime;

    private String source;

    private String tenantId;

    public static DeploymentResponse from(DeploymentEntity deployment){
        if(Objects.isNull(deployment)){
            return null;
        }
        DeploymentResponse deploymentResponse = new DeploymentResponse();
        deploymentResponse.setId(deployment.getId());
        deploymentResponse.setName(deployment.getName());
        deploymentResponse.setDeploymentTime(deployment.getDeploymentTime());
        deploymentResponse.setSource(deployment.getSource());
        deploymentResponse.setTenantId(deployment.getTenantId());
        return deploymentResponse;
    }
}
